package com.glory.study.dao.mapper.db1;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;

/*
通用分页
 */
@Mapper
@Repository
public interface PageDao {

    @Select("select count(1) from ${table}")
    int findCountAll(@Param("table") String table);

    @Select("select * from ${table} limit #{pagestart}, #{pagesize}")
    List<HashMap<String, Object>> findMapPageAll(@Param("table") String table, @Param("pagestart") int pagestart, @Param("pagesize") int pagesize);

    @Select("select count(1) from ${table} where ${strWhere}")
    int findCount(@Param("table") String table, @Param("strWhere") String strWhere);

    @Select("select ${fileds} from ${table} where ${strWhere} ${order} limit #{pagestart}, #{pagesize}")
    List<HashMap<String, Object>> findMapPage(@Param("table") String table,
                                              @Param("fileds") String fileds,
                                              @Param("order") String order,
                                              @Param("strWhere") String strWhere,
                                              @Param("pagestart") int pagestart,
                                              @Param("pagesize") int pagesize);

    @Select("select ${fileds} from ${table} where ${strWhere} ${order}")
    List<HashMap<String, Object>> findMapAll(@Param("table") String table,
                                             @Param("fileds") String fileds,
                                             @Param("order") String order,
                                             @Param("strWhere") String strWhere
    );


}

